var express = require('express')
var compression = require('compression')
var httpProxy = require('http-proxy')
var http = require('http');
var fs = require('fs')
var path = require('path')
var proxy = httpProxy.createProxyServer({})
var port = process.env.PORT || 7777
var app = express()

app.use(compression())
app.use(express.static(__dirname));

proxy.on('error', function (err, req, res) {
  console.error(err.toString());
  res.writeHead(500, { 'Content-Type': 'text/plain' })
  res.end('Something went wrong. And we are reporting a custom error message.')
})

// function proxyToBackend(req, res) {
//   proxy.web(req, res, { target: 'http://dev.wsclass.com:8080' });
// }
// app.all('/okkaozheng/app/*', proxyToBackend);
app.use(express.static('build'))
app.get('/callupV2*', function(req, res) {
  res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
var server = http.createServer(app);
server.listen(port, function () {
  console.log( 'https on 443' );
} );

